<% content_for :left_sidebar do  %>
  <%= render :partial => "layouts/sidebar/xiwenguanli" %>
<% end %>
<%- model_class = News -%>
<div class="page-header">
  <h1>媒体华理稿件列表</h1>
</div>
<%= new_button url: new_admins_meiti_path %>
<table class="table table-striped">
  <thead>
    <tr>
      <th>ID</th>

      <th>主标题</th>
      <th>来稿时间</th>
      <th>发稿人</th>
      <th>操作</th>

    </tr>
  </thead>
  <tbody>
    <% @meitis.each do |news| %>
      <tr>
        <td><%= news.id %></td>
        <td><%= link_to truncate(news.title,:length => 30),news_path(news),:target => '_blank' %></td>
        <td><%= news.pubtime.strftime('%Y/%m/%d') rescue nil %></td>
        <td><%= news.postby %></td>
        <td>
          <%= link_to "编辑",edit_admins_meiti_path(news),:class => 'btn btn-default btn-xs' %>
          <%= link_to "删除",admins_meiti_path(news),
                      :method => :delete,
                      :data => { :confirm => '确定删除?' },
                      :class => 'btn btn-xs btn-danger' %>
                      
           <%if current_user.admin? || current_user.meitihuali?%>
                <%=link_to '修改发布时间',"javascript:void(0)",onclick:'change_time(this)' %>
          <%end %>
          <div class="change_time" style="display:none;position: absolute;
                  margin-top: -100px;
                  margin-left: 80px;
                  border: 1px solid gray;
                  padding: 5px;
                  background: white;" >

            <%= form_for(:news,url:change_time_admins_meiti_path(news), method:'post') do%>
                <span>输入新时间<input  type="text" name="new_time"  onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})" readonly/></span><br/>
                <input type="button"  name="btn" onclick="submit_it(this)" value="修改" />
            <% end %>
             </div>
        </td>
      </tr>
    <% end %>
  </tbody>
</table>
<%= paginate @meitis %>


<script src="/My97DatePicker/WdatePicker.js"></script>
<script>

function submit_it(obj){
   var name =$(obj).parent().find("input[name=new_time]").val();
       $(obj).parent().submit();
}
  function change_time(obj){
      var ct =$(obj).parent().find(".change_time");

      if(ct.css('display')=='none'){
          $(".change_time").hide();
          ct.show();
      }else
      {
          ct.hide();
      }

  }
</script>
